<?php
require_once '../config/config.php';
require_once '../config/connexion_db.php';
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="utf-8">
        <title>Liste des rendez-vous</title>
        <link href="../bootstrap/css/bootstrap.css" type="text/css" rel="stylesheet">
        <link href="../css/style.css" type="text/css" rel="stylesheet">
    </head>
    <body>
         <a id="haut"></a>
        <?php require_once "../config/css_js_bootstrap/css_js_bootstrap.php"; 
        
        require_once '../config/menus/menu_principal.php';
        
        
        if(isset($_GET["tous"])) {
        $sql = "SELECT * FROM rendez_vous, contacts WHERE rendez_vous.id_contact = contacts.id";
        }
        elseif(isset($_GET["croissant"])) {
        $sql = "SELECT * FROM rendez_vous, contacts WHERE rendez_vous.id_contact = contacts.id ORDER BY rdv_date ASC";
        }
        elseif(isset($_GET["decroissant"])) {
        $sql = "SELECT * FROM rendez_vous, contacts WHERE rendez_vous.id_contact = contacts.id ORDER BY rdv_date DESC";
        }
        else {
             $sql = "SELECT * FROM contacts, rendez_vous  WHERE contacts.id = rendez_vous.id_contact"; 
        }
        
        $envoi_requete = mysqli_query($connexion_serveur, $sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
        $nbre= mysqli_num_rows($envoi_requete);
                
   ?>  
        <br><div id="div2">
        <h3>LISTE DES RENDEZ-VOUS</h3>
                Nombre de rendez-vous affichés : <span><?php echo $nbre; ?></span> 
        </div><br>
        <div id="div2">
            <form>
                <input class="btn btn-default" type="button" value="Afficher tous" onclick="window.location.href='../rendez_vous/liste_rdv.php?tous'">
                <input class="btn btn-default" type="button" value="Tri par date croissant" onclick="window.location.href='../rendez_vous/liste_rdv.php?croissant'">
                <input class="btn btn-default" type="button" value="Tri par date décroissant" onclick="window.location.href='../rendez_vous/liste_rdv.php?decroissant'">
            </form>
                <br>
            
        </div>
    <?php 
        while($resultats = mysqli_fetch_assoc($envoi_requete)) {
                ?>
            <div id="div1"> 
     <table>
            <tr>
                <td class="col1"> Contact</td>
                <td class="col2"><?php echo $resultats['nom'];?>  <?php echo $resultats['prenom']; ?></td>
            </tr>
            <tr>
                 <td class="col1">Objet</td>
                 <td class="col2"><?php echo $resultats['objet'];  ?></td>
            </tr>
            <tr>
                 <td class="col1">Date</td>
                 <td class="col2"><?php echo $resultats['rdv_date'];  ?></td>
            </tr>
            <tr>
                 <td class="col1">Heure</td>
                 <td class="col2"><?php echo $resultats['heure'];  ?></td>
            </tr>
            <tr>
                 <td class="col1">Type de RDV</td>
                 <td class="col2"><?php echo $resultats['type_rdv'];  ?></td>
            </tr>
            <tr>
                 <td class="col1">Observations</td>
                 <td class="col2"><?php echo $resultats['observations'];  ?></td>
            </tr>
            <tr>
                <td class="col1"></td>
                <td class="col2"> <a href="../rendez_vous/modifier_rdv.php?ids=<?php echo $resultats['id_contact'];?>" >Modifier</a></td>
            </tr>
        </table>
        <br>
            </div>
        
                <?php
            }
        ?>
 <a href="#haut">Haut de page</a>
    </body>
</html>
